package com.elong.businesstravel.modules.home.ticket.adapter;

import java.util.List;

import org.w3c.dom.Text;

import com.android.support.jhf.utils.DateUtils;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.baseadapter.CustomAdapter;
import com.elong.businesstravel.entitys.TrainTicket;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 火车票列表adapter
 * 
 * @author lenovo
 * 
 */
public class TicketListAdapter extends CustomAdapter {

	private List<TrainTicket> mTrainTickets;

	public TicketListAdapter(Context context, List<TrainTicket> trainTickets) {
		super(context);
		mTrainTickets = trainTickets;
	}

	@Override
	public int getCount() {
		return mTrainTickets.size();
	}

	@Override
	public Object getItem(int position) {
		return mTrainTickets.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.adapter_ticket_list, null);
		}

		TrainTicket trainTicket = mTrainTickets.get(position);

		TextView startDateTextView = (TextView) convertView
				.findViewById(R.id.startDateTextView);
		startDateTextView.setText(trainTicket.from.time);

		TextView endDateTextView = (TextView) convertView
				.findViewById(R.id.endDateTextView);
		endDateTextView.setText(trainTicket.to.time);

		TextView duringTextView = (TextView) convertView
				.findViewById(R.id.duringTextView);
		duringTextView.setText(DateUtils.dateFormat(
				Long.parseLong(trainTicket.duration), "HH时mm分"));

		TextView ticketNameTextView = (TextView) convertView
				.findViewById(R.id.ticketNameTextView);
		ticketNameTextView.setText(trainTicket.number);

		TextView startCityTextView = (TextView) convertView
				.findViewById(R.id.startCityTextView);
		startCityTextView.setText(trainTicket.from.name);

		TextView endCityTextView = (TextView) convertView
				.findViewById(R.id.endCityTextView);
		endCityTextView.setText(trainTicket.to.name);

		TextView moneyTextView = (TextView) convertView
				.findViewById(R.id.moneyTextView);
		moneyTextView.setText("￥" + trainTicket.lowPrice + "起");

		TextView ticketTypeTextView = (TextView) convertView
				.findViewById(R.id.ticketTypeTextView);
		if (null != trainTicket.getSeats() && trainTicket.getSeats().size() > 0) {
			ticketTypeTextView.setText(trainTicket.getSeats().get(0).name);
		} else {

		}
		
		TextView ticketStateTextView = (TextView)convertView.findViewById(R.id.ticketStateTextView);
		ticketStateTextView.setText(trainTicket.ticketYpName);

		return convertView;
	}

}
